package cn.kgc.crowdfundingadmin.service;

import cn.kgc.crowdfundingadmin.mapper.MessageMapper;
import cn.kgc.crowdfundingadmin.pojo.Message;
import cn.kgc.crowdfundingadmin.pojo.MessageExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class MessageServiceImpl implements MessageService {

    @Resource
    MessageMapper messageMapper;
    @Override
    public PageInfo<Message> queryForKeywordWithPage(Integer pageNum, Integer pageSize, String keyword) {
        //开启分页功能
        PageHelper.startPage(pageNum,pageSize);
        //执行查询
        MessageExample messageExample=new MessageExample();
        MessageExample.Criteria criteria=messageExample.createCriteria();
        criteria.andContentLike("%"+keyword+"%");
        List<Message> list=messageMapper.selectByExample(messageExample);
        //封装为pageInfo对象
        return new PageInfo<>(list);
    }

    //根据id查询
    @Override
    public List<Message> getCertListByIdList(List<Integer> certIdList) {
        //创建实体类message对应的Example对象
        MessageExample certExample=new MessageExample();
        //在Example对象中封装查询条件
        certExample.createCriteria().andIdIn(certIdList);
        //执行查询
        return messageMapper.selectByExample(certExample);
    }

    //修改
    @Override
    public void updateMessage(Message message) {
        messageMapper.updateByPrimaryKey(message);
    }
}
